package com.yuhanginfo.modules.sys.service;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yuhanginfo.common.persistence.Page;
import com.yuhanginfo.common.service.CrudService;
import com.yuhanginfo.modules.sys.entity.ReturnGoodsDetail;
import com.yuhanginfo.modules.sys.entity.ReturnsGoods;
import com.yuhanginfo.modules.sys.customexception.CustomException;
import com.yuhanginfo.modules.sys.dao.ReturnGoodsDetailDao;
import com.yuhanginfo.modules.sys.dao.ReturnsGoodsDao;

/**
 * 
 * 
 * @author yinhao
 * @version 2017-10-13
 */
@Service
@Transactional(readOnly = true)
public class OrdersExchangeHistoryService extends CrudService<ReturnsGoodsDao, ReturnsGoods> {
	
	@Autowired
	private ReturnsGoodsDao returnsGoodsDao;

	@Autowired
	private ReturnGoodsDetailDao returnGoodsDetailDao;
	
	

	public Page<ReturnsGoods> findPage(Page<ReturnsGoods> page, ReturnsGoods returnsGoods) {
		returnsGoods.setPage(page);
		page.setList(returnsGoodsDao.findListBySysUser(returnsGoods));
		return page;
	}

	public List<ReturnGoodsDetail> findList(ReturnGoodsDetail returnGoodsDetail) {
		return returnGoodsDetailDao.findList(returnGoodsDetail);
	}
	
	public Map<String, Object> findDetail(ReturnsGoods returnsGoods) throws CustomException {
		Map<String, Object> resultMap = new HashMap<>();
		ReturnsGoods returnsGoodsResult = returnsGoodsDao.getByCode(returnsGoods);
		resultMap.put("returnsGoods", returnsGoodsResult);
		if("1".equals(returnsGoodsResult.getOrdersType())){
			resultMap.put("detailCount", returnsGoodsDao.findReturnGoodsDetail(returnsGoods));
		}else if("2".equals(returnsGoodsResult.getOrdersType())){
			resultMap.put("detailCount", returnsGoodsDao.findReturnGoodsDetailCombo(returnsGoods));
		}else{
			resultMap.put("resultCode", "0");
			resultMap.put("resultMessage", "order_type错误");
		}
		
		return resultMap;
	}
}